package com.ruoyi.web.controller.monitor;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.VideoParseLog;
import com.ruoyi.system.service.IVideoParseLogService;

/**
 * 短视频解析日志Controller
 * 
 * @author ruoyi
 * @date 2025-01-15
 */
@RestController
@RequestMapping("/monitor/videoParseLog")
public class VideoParseLogController extends BaseController
{
    @Autowired
    private IVideoParseLogService videoParseLogService;

    /**
     * 查询短视频解析日志列表
     */
    @PreAuthorize("@ss.hasPermi('monitor:videoParseLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(VideoParseLog videoParseLog)
    {
        startPage();
        List<VideoParseLog> list = videoParseLogService.selectVideoParseLogList(videoParseLog);
        return getDataTable(list);
    }

    /**
     * 导出短视频解析日志列表
     */
    @PreAuthorize("@ss.hasPermi('monitor:videoParseLog:export')")
    @Log(title = "短视频解析日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, VideoParseLog videoParseLog)
    {
        List<VideoParseLog> list = videoParseLogService.selectVideoParseLogList(videoParseLog);
        ExcelUtil<VideoParseLog> util = new ExcelUtil<VideoParseLog>(VideoParseLog.class);
        util.exportExcel(response, list, "短视频解析日志数据");
    }

    /**
     * 获取短视频解析日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('monitor:videoParseLog:query')")
    @GetMapping(value = "/{logId}")
    public AjaxResult getInfo(@PathVariable("logId") Long logId)
    {
        return success(videoParseLogService.selectVideoParseLogByLogId(logId));
    }

    /**
     * 新增短视频解析日志
     */
    @PreAuthorize("@ss.hasPermi('monitor:videoParseLog:add')")
    @Log(title = "短视频解析日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody VideoParseLog videoParseLog)
    {
        return toAjax(videoParseLogService.insertVideoParseLog(videoParseLog));
    }

    /**
     * 修改短视频解析日志
     */
    @PreAuthorize("@ss.hasPermi('monitor:videoParseLog:edit')")
    @Log(title = "短视频解析日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody VideoParseLog videoParseLog)
    {
        return toAjax(videoParseLogService.updateVideoParseLog(videoParseLog));
    }

    /**
     * 删除短视频解析日志
     */
    @PreAuthorize("@ss.hasPermi('monitor:videoParseLog:remove')")
    @Log(title = "短视频解析日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{logIds}")
    public AjaxResult remove(@PathVariable Long[] logIds)
    {
        return toAjax(videoParseLogService.deleteVideoParseLogByLogIds(logIds));
    }

    /**
     * 清空短视频解析日志
     */
    @PreAuthorize("@ss.hasPermi('monitor:videoParseLog:remove')")
    @Log(title = "短视频解析日志", businessType = BusinessType.CLEAN)
    @DeleteMapping("/clean")
    public AjaxResult clean()
    {
        videoParseLogService.cleanVideoParseLog();
        return success();
    }

    /**
     * 根据小程序ID统计解析次数
     */
    @PreAuthorize("@ss.hasPermi('monitor:videoParseLog:list')")
    @GetMapping("/countByMiniprogram/{miniprogramId}")
    public AjaxResult countByMiniprogram(@PathVariable String miniprogramId)
    {
        Long count = videoParseLogService.countByMiniprogramId(miniprogramId);
        return success(count);
    }

    /**
     * 根据平台统计解析次数
     */
    @PreAuthorize("@ss.hasPermi('monitor:videoParseLog:list')")
    @GetMapping("/countByPlatform/{platform}")
    public AjaxResult countByPlatform(@PathVariable String platform)
    {
        Long count = videoParseLogService.countByPlatform(platform);
        return success(count);
    }
}
